// JavaScript Document
function InsertText() { var editor = CKEDITOR.instances.editor1; var value = document.getElementById('textarea').value;
if ( editor.mode == 'wysiwyg' ){editor.insertText( value );}else alert( 'You must be in WYSIWYG mode!' );}
function onFocus() {document.getElementById( 'eMessage' ).innerHTML = '';}
function onBlur() {document.getElementById( 'eMessage' ).innerHTML = this.name + ' lost focus';}

var popupStatus = 0;
function loadPopup() {
    if(popupStatus==0) {
        $("#backgroundPopup").css({"opacity": "0.9"});
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}
function disablePopup() {
    if(popupStatus==1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}
function centerPopup(position) {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    $("#popupContact").css({
        "position": position,
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
    $("#backgroundPopup").css({"height": windowHeight});
}

$(document).ready(function() {
	$("#popupContactClose").click(function(){ disablePopup(); });
	$("#backgroundPopup").click(function(){ disablePopup(); });
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1) disablePopup();
	});
	$(window).bind('resize', function(){ centerPopup("absolute"); });
	
	function quan_huyen(tinh_tp,quan_huyen,check){
		var tinhthanh = $('select[name='+tinh_tp+']').val();
		var check = $('input[name='+check+']').val();
		$.post('ajax.php',{tinhthanh:'tinhthanh',id:tinhthanh,check:check},function(data){ 
			$('select[name='+quan_huyen+']').html(data);
		});
		$('select[name='+tinh_tp+']').change(function(){ 
			var tinhthanh = $(this).val(); 
			$.post('ajax.php',{tinhthanh:'tinhthanh',id:tinhthanh},function(data){ 
				$('select[name='+quan_huyen+']').html(data);
			});
		});
	}
	quan_huyen('tinhthanh','quanhuyen',null);/* login */
	quan_huyen('tinh_tp','quan_huyen','check'); /* info me*/
	
	if(navigator.appName!="Microsoft Internet Explorer"){
		$(".info, .comment").corner("top 5px");
		$("#status").corner("5px");
	}
	$("#notification").click(function(){
		var status = $(this).attr("status");
		if(status==1){
			$(this).attr("status","0");
			$("#view_notification").css("visibility","visible");
		}else{
			$(this).attr("status","1");
			$("#view_notification").css("visibility","hidden");
		}
	});
});